package com.huangwenshuo.futurestarschoolmanagement.service.impl;

import com.huangwenshuo.futurestarschoolmanagement.pojo.dto.CoursewareDto;
import com.huangwenshuo.futurestarschoolmanagement.pojo.po.Classes;
import com.huangwenshuo.futurestarschoolmanagement.pojo.po.Courseware;
import com.huangwenshuo.futurestarschoolmanagement.mapper.CoursewareMapper;
import com.huangwenshuo.futurestarschoolmanagement.pojo.vo.CoursewareVo;
import com.huangwenshuo.futurestarschoolmanagement.service.CoursewareService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huangwenshuo.futurestarschoolmanagement.service.StudentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author huangwenshuo
 * @since 2021-03-07
 */
@Service
public class CoursewareServiceImpl extends ServiceImpl<CoursewareMapper, Courseware> implements CoursewareService {

    @Autowired
    private CoursewareMapper coursewareMapper;


    @Override
    public Map<String, Object> getFlies(CoursewareDto.CPage cPage) {
        Map<String,Object> res = new HashMap<>();
        int page = cPage.getPage();
        cPage.setPage((cPage.getPage()-1)*cPage.getRow());
        cPage.setRow(page*cPage.getRow());
        List<CoursewareVo> coursewareVos = coursewareMapper.getFlies(cPage);
        int total = coursewareMapper.getFliesTotal(cPage);
        List<Classes> classes = coursewareMapper.getClasses(cPage.getUid());
        List<String> fos = coursewareMapper.getFos(cPage.getUid());
        res.put("coursewareVos",coursewareVos);
        res.put("total",total);
        res.put("classes",classes);
        res.put("fos",fos);
        return res;
    }

    @Override
    public void addFiles(CoursewareDto.CPage page) {
        String[] ss = page.getFurl().split("\\.");
            page.setFtype(ss[ss.length-1]);
            coursewareMapper.addFiles(page);
    }

    @Override
    public void updateFile(CoursewareDto.CPage page) {
        String[] ss = page.getFurl().split("\\.");
        page.setFtype(ss[ss.length-1]);
        coursewareMapper.updateFile(page);
    }

    @Override
    public void delFile(CoursewareDto.CPage page) {
        coursewareMapper.delFile(page);
    }

    public static void main(String[] args) {
        String a = "https://package-by-hws.oss-cn-beijing.aliyuncs.com/fssm/cc80d976d19049ccaffcfd1a58b248ee.jpg";
        String[] ss = a.split("\\.");
        System.out.println(ss[ss.length-1]);
    }
}
